# encoding: utf-8
# Author    : limusen
# Datetime  : 2023/10/19 10:19
# File      : demo1.py
# explain   : 文件说明

import time

from selenium.webdriver.common.by import By
from common.config import local_config
from common.browse import Browser
from common.base import Base
from page_objects.locator import register_locator as rg
import requests

driver = Browser().get_driver()

bs = Base(driver)
#
bs.open_url('/simple/reg')
bs.set_window_max()
time.sleep(2)
res = bs.get_attribute(rg.get_captcha,'src')
# print(res)

code = requests.get(res)
# print(code.content)


with open('./code.png','wb') as file:
    file.write(code.content)

time.sleep(2)

# bs.get_page_img()
# element = bs.get_element((By.XPATH, '//*[@id="captchaImg"]'))
# print(element.location)                # 打印元素坐标
# print(element.size)                    # 打印元素大小



# left = element.location['x']
# top = element.location['y']
# right = element.location['x'] + element.size['width']
# bottom = element.location['y'] + element.size['height']
#
# print(left)
# print(top)
# print(right)
# print(bottom)

# im = Image.open('bdbutton.png')
# im = im.crop((left, top, right, bottom))
# im.save('bdbutton.png')

# res = bs.request('get', '/site/getCaptcha/random/0.934524083812214')
# code = bs.process_and_recognize_image(res.content)
#
# bs.send_keys(rg.username, 'limsx')
# bs.send_keys(rg.password, 111111)
# bs.send_keys(rg.re_password, 111111)
# time.sleep(3)
# bs.send_keys(rg.captcha , code)
# print(res.text)
# time.sleep(5)

